@@ -237,9 +237,16 @@ module Agents |
||
237 | 237 |
|
238 | 238 |
def receive(incoming_events) |
239 | 239 |
incoming_events.each do |event| |
240 |
+ Thread.current[:current_event] = event |
|
240 | 241 |
url_to_scrape = event.payload['url'] |
241 | 242 |
check_url(url_to_scrape) if url_to_scrape =~ /^https?:\/\//i |
242 | 243 |
end |
244 |
+ ensure |
|
245 |
+ Thread.current[:current_event] = nil |
|
246 |
+ end |
|
247 |
+ |
|
248 |
+ def interpolated(event = Thread.current[:current_event]) |
|
249 |
+ super |
|
243 | 250 |
end |
244 | 251 |
|
245 | 252 |
private |
@@ -453,16 +453,32 @@ fire: hot |
||
453 | 453 |
end |
454 | 454 |
|
455 | 455 |
describe "#receive" do |
456 |
- it "should scrape from the url element in incoming event payload" do |
|
456 |
+ before do |
|
457 | 457 |
@event = Event.new |
458 | 458 |
@event.agent = agents(:bob_rain_notifier_agent) |
459 | 459 |
@event.payload = { 'url' => "http://xkcd.com" } |
460 |
+ end |
|
460 | 461 |
|
462 |
+ it "should scrape from the url element in incoming event payload" do |
|
461 | 463 |
lambda { |
462 | 464 |
@checker.options = @valid_options |
463 | 465 |
@checker.receive([@event]) |
464 | 466 |
}.should change { Event.count }.by(1) |
465 | 467 |
end |
468 |
+ |
|
469 |
+ it "should interpolate values from incoming event payload" do |
|
470 |
+ @event.payload['title'] = 'XKCD' |
|
471 |
+ |
|
472 |
+ lambda { |
|
473 |
+ @valid_options['extract']['site_title'] = { |
|
474 |
+ 'css' => "#comic img", 'value' => "'{{title}}'" |
|
475 |
+ } |
|
476 |
+ @checker.options = @valid_options |
|
477 |
+ @checker.receive([@event]) |
|
478 |
+ }.should change { Event.count }.by(1) |
|
479 |
+ |
|
480 |
+ Event.last.payload['site_title'].should == 'XKCD' |
|
481 |
+ end |
|
466 | 482 |
end |
467 | 483 |
end |
468 | 484 |
|